<template>
  <div id="rose-chart">
    <div class="rose-chart-title">成果类型分布</div>
    <dv-charts :option="option" />
  </div>
</template>

<script>
  import { fenbu } from "@/api/module/gs/dashuju";
export default {
  name: 'RoseChart',
  data () {
    return {
      cxtotal:0,
      cytotal:0,
      cysjtotal:0,
      option: {}
    }
  },
  created() {
    this.getfenbu()
  },
  methods: {
    getfenbu(){
      fenbu(this.queryParams).then((response) => {
        console.log(response.cxtotal+"aaa")
        console.log(response.cytotal+"ppp")
        console.log(response.cysjtotal+"ppp")
        this.cxtotal = response.cxtotal;
        this.cytotal = response.cytotal;
        this.cysjtotal = response.cysjtotal;
      }).then((response) => {
        const { createData } = this

        createData()

        setInterval(createData, 30000)
      })
    },
    createData () {
      const { randomExtend } = this

      this.option = {
        series: [
          {
            type: 'pie',
            radius: '75%',
            roseSort: false,
           /* data: [
              { name: '创新训练项目', value:  this.cxtotal },
              { name: '创业训练项目', value:  this.cytotal},
              { name: '创业实践项目', value:  this.cysjtotal},
            ],*/
            data: [
              { name: '创新训练项目', value:  33 },
              { name: '创业训练项目', value:  33},
              { name: '创业实践项目', value:  34},
            ],
            insideLabel: {
              show: false
            },
            outsideLabel: {
              formatter: '{name} {percent}%',
              labelLineEndLength: 20,
              style: {
                fill: '#fff',
                fontSize: 17 // 设置字体大小，单位为像素
              },
              labelLineStyle: {
                stroke: '#fff'
              }
            },
            roseType: true
          }
        ],
        color: [ '#fa3600', '#ff4411', '#ff724c', ]
      }
    },
    randomExtend (minNum, maxNum) {
      if (arguments.length === 1) {
        return parseInt(Math.random() * minNum + 1, 10)
      } else {
        return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
      }
    }
  },
/*  mounted () {
    const { createData } = this

    createData()

    setInterval(createData, 30000)
  }*/
}
</script>

<style lang="less">
#rose-chart {
  width: 50%;
  height: 100%;
  background-color: rgba(6, 30, 93, 0.5);
  border-top: 2px solid rgba(1, 153, 209, .5);
  box-sizing: border-box;

  .rose-chart-title {
    font-weight: bold;
    height: 50px;
    display: flex;
    align-items: center;
    font-size: 20px;
    justify-content: center;
  }

  .dv-charts-container {
    height: calc(~"100% - 50px");
  }
}
</style>
